<-- back

Palindrome Number

Link

Storing the first character in variable a and the last character in b. Then we just compare them and determine if they're a palindrome.

Full Solution in Java:

public class Solution { public boolean isPalindrome(int x) { if(x<0){ return false; } int size = (int)(Math.log(x)/Math.log(10))+1; int temp = size; for(int i=0; i< size/2; i++){ int a = (x/(int)(Math.pow(10,temp-1)))%10; int b = x%10; x/=10; temp-=2; if(a!=b){ return false; } } return true; } }